package com.xique.door.controller;

import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.door.bean.request.estate.EstateUserAddRequest;
import com.xique.door.bean.request.estate.EstateUserEditRequest;
import com.xique.door.bean.request.estate.EstateUserListRequest;
import com.xique.door.biz.service.IEstateUserBizService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author shd
 * @create 2022/6/9 13:19
 */
@RestController
@RequestMapping("/estate/user")
public class EstateUserController extends BaseController {

    @Autowired
    private IEstateUserBizService estateUserBizService;

    /**
     * 获取物业用户列表
     */
    @PreAuthorize(hasPermi = "door:estateUser:list")
    @GetMapping("/list")
    public AjaxResult list(EstateUserListRequest request) {
        request.setParkId(SecurityUtils.getParkId());
        return estateUserBizService.getEstateUserList(request);
    }

    /**
     * 获取物业用户详细信息
     */
    @PreAuthorize(hasPermi = "door:estateUser:query")
    @GetMapping("/detail")
    public AjaxResult detail(Long id) {
        return estateUserBizService.getEstateUserDetail(id);
    }

    /**
     * 新增物业用户
     */
    @PreAuthorize(hasPermi = "door:estateUser:add")
    @Log(title = "物业用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Valid EstateUserAddRequest request) {
        request.setParkId(SecurityUtils.getParkId());
        return estateUserBizService.addEstateUser(request);
    }


    /**
     * 修改物业用户
     */
    @PreAuthorize(hasPermi = "door:estateUser:edit")
    @Log(title = "物业用户", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody @Valid EstateUserEditRequest request) {
        return estateUserBizService.editEstateUser(request);
    }

    /**
     * 删除物业用户
     */
    @PreAuthorize(hasPermi = "door:estate_user:remove")
    @Log(title = "物业用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove")
    public AjaxResult remove(Long id) {
        return estateUserBizService.removeEstateUser(id);
    }

    @PreAuthorize(hasPermi = "door:estateUser:query")
    @GetMapping("/command/download")
    public AjaxResult download(Long id) {
        return estateUserBizService.downEstateUser(id);
    }
}
